// 封装一个 axios 请求模块
import axios from "axios";
import store from "@/store";

const requert = axios.create({
  baseURL: "http://geek.itheima.net/",
});

// 请求拦截器
requert.interceptors.request.use(
  function (config) {
    const { user } = store.state;
    if (user && user.token) {
      config.headers.Authorization = `Bearer ${user.token}`;
    }
    return config;
  },
  function (error) {
    // 如果请求出错了（还没有发出去）会进入这里
    return Promise.reject(error);
  }
);

export default requert;
